<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/25
 * Time: 9:34
 */
namespace app\team\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Session;
use app\team\model\Team;
class Info extends Common
{
    /*
     * 旅行社介绍列表
     */
    public function info()
    {
        if (Request::instance()->isAjax()) {

            $where['team_id'] = Session::get('team')['team_id'];
            $filed = ['team_id','team_name','team_icon',
                'team_phone','team_address','team_start_time',
                'team_end_time','team_background','team_bank_card','team_bank_name','city'];
            $data = Team::getTeamList($where,$filed);

            return json(array('code'=>0,'msg'=>'请求成功','data'=>$data));
        } else {
            return view();
        }
    }

    /*
     * 完善旅行社信息
     */
    public function editInfo()
    {
        if(Request::instance()->isAjax()){
            $post = Request::instance()->post();
            $post = $post['data'];
            if(empty($post['team_background']) || empty($post['team_icon'])){
                return ['code'=>1,'msg'=>'上传的内容不能为空'];
            }
            $where = "team_id = {$post['team_id']}";
            $data = [
                'team_name'=>$post['team_name'],
                'team_phone'=>$post['team_phone'],
                'team_icon'=>$post['team_icon'],
                'team_background'=>$post['team_background'],
                'city'=>$post['province'].$post['city'].$post['district'],
                'team_address'=>$post['team_address'],
                'team_start_time'=>$post['team_start_time'],
                'team_end_time'=>$post['team_end_time'],
            ];
            $res = Db::name('team')->where($where)->update($data);
            if($res){
                return ['code'=>0,'msg'=>'修改成功'];
            }else{
                return ['code'=>2,'msg'=>'修改失败'];
            }
        }else{
            $id = input('id');
            $res = Team::getTourById($id);
            $this->assign('res',$res);
            return view();
        }

    }
}